
import sys
import myhelper 

def extract_int( extractor, fn, ignore_below, ignore_up ):
    values = myhelper.get_key_value_from_file_int( extractor, fn, ignore_below, ignore_up)
    print "key:%s file:%s mean:%s min:%s max:%s count:%s sum:%s sigma:%s"%( extractor, fn, myhelper.mean( values ), min( values ), max( values ), len( values ), sum( values ), myhelper.standard_deviation( values ) )
    values.sort()
    total_cnt = len( values )
    per_cnt = int(float(total_cnt) / 100)
    if per_cnt<1:
        per_cnt = 1
    first_per_values = values[0:per_cnt]
    last_per_values  = values[total_cnt-per_cnt: total_cnt]
    print "first percentile mean:%s min:%s max:%s count:%s sum:%s"%( myhelper.mean( first_per_values ), min( first_per_values ), max( first_per_values ), len( first_per_values ), sum( first_per_values ) )
    print "last percentile mean:%s min:%s max:%s count:%s sum:%s"%( myhelper.mean( last_per_values ), min( last_per_values ), max( last_per_values ), len( last_per_values ), sum( last_per_values ) )

if __name__=="__main__":
    ignore_below = -1
    ignore_up = -1
    fn = ''
    if len( sys.argv )==3:
        fn = sys.argv[1]
        extractor = sys.argv[2]
    elif len( sys.argv )==5:
        fn = sys.argv[1]
        extractor = sys.argv[2]
        ignore_below = int( sys.argv[3] )
        ignore_up = int( sys.argv[4] )
    else:
        print "invalide arguments. Usage: extract_float_lite.py file extractor [ignore_below ignore_up]"
    extract_int( extractor, fn, ignore_below, ignore_up )

